<template>
	<view>
		<cu-custom :isBack="false" bgColor="HomePageStyle">
			<block slot="content">分类</block>
		</cu-custom>

		<view class="classificationBox">
			<view class="SearchBox">
				<view class="Search">
					<img :src="imgUrl + gameDetailsData.Classification.Search" class="search" alt="" />
					<input type="text" placeholder="搜索商品" class="SearchInput" placeholder-class="placeholderStyle"
						v-model="ScreeningCondition.keyWords" @click="ToSeach" />
				</view>
			</view>

			<view class="classification">
				<view class="classificationItem default" :class="{
            Activeclassification: CurrentClassification == 'Currentdefault',
          }" @click="ChangeCurrentClassification('Currentdefault')">
					默认
				</view>

				<view class="classificationItem price" :class="{
            Activeclassification: CurrentClassification == 'Currentprice',
          }" @click="ChangeCurrentClassification('Currentprice')">
					<view class=""> 价格 </view>
					<image :src="Price[PriceSrc]" alt="" class="classificationicon"></image>
				</view>

				<view class="classificationItem SalesVolume" :class="{
            Activeclassification: CurrentClassification == 'CurrentSalesVolume',
          }" @click="ChangeCurrentClassification('CurrentSalesVolume')">
					<view class=""> 销量 </view>
					<image :src="Price[SalesVolumeSrc]" alt="" class="classificationicon"></image>
				</view>

				<view class="classificationItem screening" :class="{
            Activeclassification: CurrentClassification == 'Currentscreening',
          }" @click="ChangeCurrentClassification('Currentscreening')">
					<view class="screeningtext"> 筛选 </view>
					<img class="screeningIcon" :src="imgUrl + gameDetailsData.Classification.DropArrow" />
				</view>
			</view>

			<view class="CommodityList">
				<scroll-view :scroll-y="true" class="CommodityClassification">
					<view class="ClassificationItem" v-for="(item, index) in ClassificationList" :key="index" :class="{
              AtiveCategory: ScreeningCondition.goodsCategoryId == item.id,
            }" @click="ChangeCurrent(item.id)">
						{{ item.categoryName }}
					</view>
				</scroll-view>

				<scroll-view :scroll-y="true" class="List" refresher-default-style="none"
					@scrolltolower="scrolltolower">
					<view class="CommodityListContent">
						<view class="CommodityItem" v-for="(item, index) in CommodityList" :key="index">
							<view class="CommodityLeft" @click.stop="toShopDetails(item.goodsCode)">
								<img class="CommodityImage" :src="item.goodsSmallImage" />
							</view>
							<view class="CommodityRight" @click.stop="toShopDetails(item.goodsCode)">
								<view class="CommodityName">
									{{ item.goodsName }}
								</view>
								<view class="CommodityPriceArea">
									<view class="RMBAndPrice">￥{{ item.goodsPrice }}</view>
									<view> /个 </view>
								</view>
							</view>
						</view>
					</view>
				</scroll-view>
			</view>

			<view class="cu-modal modal stateTypeTck" :class="modalName == 'bottomModala' ? 'show' : ''"
				@click="hideModel" v-if="modalName == 'bottomModala'">
				<view class="cu-dialog" @click.stop="">
					<view class="PriceRange">
						<view class="Title"> 价格之间 </view>
						<view class="Form">
							<view class="lowestPrice">
								<view class="lowestPriceLeft Left"> 最低价(元) </view>
								<input type="text" class="lowestPriceInput" placeholder="请输入"
									v-model="ScreeningCondition.lowerPrice" />
							</view>
							<view class="highestPrice">
								<view class="highestPriceLeft Left"> 最高价(元) </view>
								<input type="text" class="highestPriceInput" placeholder="请输入"
									v-model="ScreeningCondition.highPrice" />
							</view>
						</view>

						<view class="ConfimAndClear">
							<view class="Clear" @click="ClearCondition"> 清除条件 </view>
							<view class="Confim" @click="Confim"> 确定 </view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import gameDetails from "@/static/lib/public.js";
	export default {
		data() {
			return {
				CurrentClassification: "Currentdefault",

				ClassificationList: [],

				AtiveCategory: "",

				gameDetailsData: gameDetails,

				imgUrl: this.$http.imgUrl,
				Price: {
					0: "https://lzmordershop.oss-cn-hangzhou.aliyuncs.com/static/classification/NoCurrent.jpg",
					1: "https://lzmordershop.oss-cn-hangzhou.aliyuncs.com/static/classification/Current_bottom.jpg",
					2: "https://lzmordershop.oss-cn-hangzhou.aliyuncs.com/static/classification/Current_Top.jpg",
				},

				ScreeningCondition: {
					pageNumber: 1,
					pageSize: 10,
					goodsCategoryId: 0,
					field: "",
					highPrice: "",
					keyWords: "",
					lowerPrice: "",
					orderBy: "",
					totalPage: "",
				},

				CommodityList: [],

				modalName: null,

				PriceSrc: "0",
				SalesVolumeSrc: "0",
			};
		},
		created() {
			this.getClassificationList();
			this.getCommodityList();
		},
		methods: {
			ChangeCurrentClassification(condition) {
				if (condition == "Currentprice") {
					this.SalesVolumeSrc = "0";
					if (this.PriceSrc === "0") {
						this.ScreeningCondition.field = "goods_price";
						this.ScreeningCondition.orderBy = "desc";
						this.CommodityList = [];
						this.getCommodityList();
						this.PriceSrc = "1";
					} else {
						this.PriceSrc = this.PriceSrc === "1" ? "2" : "1";
						this.ScreeningCondition.orderBy =
							this.PriceSrc === "1" ? "desc" : "asc";
						this.CommodityList = [];
						this.getCommodityList();
					}
				} else if (condition == "CurrentSalesVolume") {
					this.PriceSrc = "0";
					if (this.SalesVolumeSrc === "0") {
						this.SalesVolumeSrc = "1";
						this.ScreeningCondition.field = "goods_sales";
						this.ScreeningCondition.orderBy = "desc";
						this.CommodityList = [];
						this.getCommodityList();
					} else {
						this.SalesVolumeSrc = this.SalesVolumeSrc === "1" ? "2" : "1";
						this.ScreeningCondition.orderBy =
							this.SalesVolumeSrc === "1" ? "desc" : "asc";
						this.CommodityList = [];
						this.getCommodityList();
					}
				} else if (condition == "Currentscreening") {
					this.SalesVolumeSrc = "0";
					this.PriceSrc = "0";
					this.modalName = "bottomModala";
				} else if (condition == "Currentdefault") {
					this.PriceSrc = "0";
					this.SalesVolumeSrc = "0";
					this.CommodityList = [];
					this.getCommodityList();
				}
				this.CurrentClassification = condition;
			},
			ChangeCurrent(item) {
				this.ScreeningCondition.goodsCategoryId = item;
				this.CommodityList = [];
				this.getCommodityList();
			},
			scrolltolower(e) {
				if (
					this.ScreeningCondition.pageNumber >= this.ScreeningCondition.totalPage
				) {
					uni.showToast({
						title: "暂无数据",
						icon: "none",
					});
					return;
				}
				this.ScreeningCondition.pageNumber++;
				this.getCommodityList();
			},
			hideModel() {
				this.modalName = null;
			},
			async getClassificationList() {
				const url = this.api.classificationList.getClassificationList;
				const res = await this.$http.get(url, {});
				this.ClassificationList = res.data.data.data;
				const obj = {
					id: 0,
					categoryName: "全部分类",
				};
				this.ClassificationList.unshift(obj);
			},
			// 获取商品列表
			async getCommodityList() {
				const url = this.api.home.GoodsList;
				const res = await this.$http.get(url, {
					...this.ScreeningCondition,
				});
				this.ScreeningCondition.totalPage = res.data.data.totalPage;
				this.CommodityList = this.CommodityList.concat(res.data.data.data);
				console.log(this.CommodityList);
			},
			ClearCondition() {
				this.ScreeningCondition.highPrice = "";
				this.ScreeningCondition.lowerPrice = "";
			},
			Confim() {
				this.modalName = null;
				this.CommodityList = [];
				this.getCommodityList();
			},
			ToSeach() {
				uni.navigateTo({
					url: "/pagesA/HomePage/Search",
				});
			},
			toShopDetails(id) {
				uni.navigateTo({
					url: "/pagesA/HomePage/ShopDetails?id=" + id,
				});
			},
			zwkf() {
				uni.showToast({
					title: "暂未开放",
					duration: 2000,
					icon: "none",
				});
			},
		},
	};
</script>

<style lang="scss" scoped>
	.classificationBox {
		width: 100%;
		height: 100vh;
		position: fixed;

		.SearchBox {
			width: 100%;
			height: 80rpx;
			padding-left: 20rpx;
			padding-top: 30rpx;

			.Search {
				background-color: #f9f9fa;
				height: 50rpx;
				width: 95%;
				border-radius: 50rpx;
				display: flex;
				align-items: center;

				.search {
					width: 32rpx;
					height: 32rpx;
					margin-left: 40rpx;
					margin-right: 28rpx;
				}

				.SearchInput {
					width: 100%;
				}
			}
		}

		.classification {
			width: 100%;
			display: flex;
			justify-content: space-between;

			.classificationItem {
				width: 25% !important;
				text-align: center;
				height: 100rpx;
				line-height: 100rpx;

				.classificationicon {
					width: 30rpx !important;
					height: 30rpx !important;
				}
			}

			.price,
			.SalesVolume {
				display: flex;
				align-items: center;
				justify-content: center;
			}

			.screening {
				display: flex;
				align-items: center;
				justify-content: center;

				.screeningIcon {
					width: 16rpx;
					height: 16rpx;
					margin-left: 10rpx;
				}
			}

			.Activeclassification {
				border-bottom: 3rpx solid #376af6;
				color: #376af6;
			}
		}

		.CommodityList {
			display: flex;
			width: 100%;
			height: 100%;

			.CommodityClassification {
				width: 25%;
				background-color: #f8f8f8;
				height: 100%;
				border-right: 3rpx solid #f1f1f1;

				.ClassificationItem {
					height: 120rpx;
					text-align: start;
					padding-left: 20rpx;
					line-height: 120rpx;
					width: 100%;
				}
			}

			.List {
				width: 75%;
				height: 70%;
				background-color: #FFFFFF;

				.CommodityListContent {
					width: 100%;
					height: 100%;
					padding-top: 20rpx;

					.CommodityItem {
						height: 200rpx;
						width: 100%;
						display: flex;

						.CommodityLeft {
							width: 150rpx;
							height: 150rpx;
							margin-left: 20rpx;
							border-radius: 15rpx;

							.CommodityImage {
								width: 100%;
								height: 100%;
							}
						}

						.CommodityRight {
							flex: 1;
							width: 194rpx;
							margin-left: 20rpx;

							.CommodityName {
								// 超出省略
								overflow: hidden;
								text-overflow: ellipsis;
								white-space: nowrap;
								width: 100%;
							}

							.CommodityPriceArea {
								display: flex;
								margin-top: 60rpx;

								.RMBAndPrice {
									color: #376af6;
								}
							}
						}
					}
				}
			}
		}

		.placeholderStyle {
			color: #abacab;
			font-size: 30rpx;
		}

		.AtiveCategory {
			background-color: #FFFFFF;
			position: relative;

			&::before {
				width: 10rpx;
				height: 10rpx;
				border-radius: 50%;
				position: absolute;
				content: "";
				left: 5rpx;
				top: 50%;
				background-color: #376af6;
			}
		}

		.cu-dialog {
			width: 90%;
			height: 300rpx;
			background-color: #FFFFFF;

			.PriceRange {
				width: 100%;
				height: 100%;
				padding: 30rpx 0rpx 20rpx 20rpx;

				.Title {
					width: 100%;
					text-align: start;
					margin-right: 50rpx;
					color: #000;
					opacity: 0.4;
					font-size: 22rpx;
				}

				.Form {

					.lowestPrice,
					.highestPrice {
						text-align: start;
						height: 80rpx;
						line-height: 80rpx;
						border-bottom: 2rpx solid #efefef;
						display: flex;
						align-items: center;

						.Left {
							margin-right: 40rpx;
						}
					}

					.lowestPrice {}

					.highestPrice {}
				}

				.ConfimAndClear {
					width: 100%;
					display: flex;
					height: 80rpx;
					line-height: 80rpx;
					opacity: 0.4;

					.Clear,
					.Confim {
						width: 50%;
					}

					.Confim {}
				}
			}
		}
	}
</style>